#d ;
capture log close ;
capture program drop coint ;
capture postclose coint ;
set more off ;
clear ;
set seed 1234567891 ;
cap mkdir "Set directory here" ;
global nocoint "Set directory here" ;
cap mkdir "$nocoint\figures" ;
cap mkdir "$nocoint\results" ;


program define coint, rclass ;
syntax [, i(real 0) j(real 0) k(real 0) l(real 0) m(real 0) n(real 0) 
p(real 1) q(real 1) r(real 1) s(real 0) v(real 0) w(real 0) obs(integer 130)] ;
	#d ;
	drop _all ;
	set obs `obs' ;
	gen t = _n ;
	tsset t ;
	/*We have three variables: y, x_1, x_2.*/
	gen e_1 = invnorm(uniform()) ;
	gen x_1=e_1 if t==1 ;
	gen e_2 = invnorm(uniform()) ;
	gen x_2=e_2 if t==1 ;
	gen u=invnorm(uniform()) ;
	gen y=u if t==1 ;
	replace x_1= `q'*l.x_1+e_1 if t>1 ;
	replace x_2= `r'*l.x_2+e_2 if t>1 ;
	replace y= `p'*l.y + u if t>1 ;
		drop if t<=100 ;
		
		/*Identify appropriate lags for the Dicky-Fuller test (y). */ 
		reg d.y l.y ; 
		predict resid_y, r ;
		wntestq resid_y ;
		local i=r(p) ; 
		drop resid_y ;
		while `i'<0.05 { ; /*The "while" command allows us to keep running the set of stata commands 
		                   enclosed in the braces until the p-value from the White noise Q test becomes 
		                   greater than 0.05. */
		local j =`j'+ 1 ; /*If the p-value is lower than 0.05, which is a sign of the presence of serial correlation, 
							`j' increases by one unit such that one more lag of ld.y is added in the equation below.*/
		reg d.y l.y l(1/`j')d.y ; 
		predict resid_y, r ;
		wntestq resid_y ;
		local i=r(p) ; 
		drop resid_y ;
		} ;
		
		/*Identify appropriate lags for the Dicky-Fuller test (x_1). */ 
		reg d.x_1 l.x_1 ; 
		predict resid_x_1, r ;
		wntestq resid_x_1 ;
		local k=r(p) ; 
		drop resid_x_1 ;
		while `k'<0.05 { ; 
		local l=`l'+ 1 ; 
		reg d.x_1 l.x_1 l(1/`l')d.x_1 ; 
		predict resid_x_1, r ;
		wntestq resid_x_1 ;
		local k=r(p) ; 
		drop resid_x_1 ;
		} ;
		
		/*Identify appropriate lags for the Dicky-Fuller test (x_2). */ 
		reg d.x_2 l.x_2 ; 
		predict resid_x_2, r ;
		wntestq resid_x_2 ;
		local k=r(p) ; 
		drop resid_x_2 ;
		while `k'<0.05 { ; 
		local v=`v'+ 1 ; 
		reg d.x_2 l.x_2 l(1/`v')d.x_2 ; 
		predict resid_x_2, r ;
		wntestq resid_x_2 ;
		local k=r(p) ; 
		drop resid_x_2 ;
		} ;

		
		/*Augmented Dicky-Fuller test */
		dfuller y, lags(`j') ; /*dfuller: dfuller=Dickey-Fuller (DF) Test
					H0: I(1) or y is unit root.
					H1: (p-1)<0 or y is stationary.
					The appropriate lags `j' is imputed so as to address 
					the issues of serial correlation.
					If p-value is greater than 0.05, it indicates that y
					has a unit root.
					Note that rejecting the null hypothesis does not mean
					we can accept H0 (Woodridge 2009, 633)!
					dfuller by default regresses d.y on l.y. 
					How many lags to be included often depends on 
					the frequency of the data.*/
		
		return scalar p_value_df_y=r(p) ; /*Save p-value to see if the 
										estimated coefficient on l.y is 
										statistically significant at the .05 level 
										given the Dicket-Fuller Distribution.*/
		
		dfuller x_1, lags(`l') ;
		return scalar p_value_df_x_1=r(p) ; 
		
		dfuller x_2, lags(`v') ;
		return scalar p_value_df_x_2=r(p) ; 
		
			
		/*Error Correction Model (ECM)*/
		reg d.y l.y d.x_1 d.x_2 l.x_1 l.x_2 ;
		return scalar beta_ly = _b[l.y] ; /*Save these coefficients to check bias.*/
		local beta_ly=_b[L.y] ;
		return scalar beta_lx_1 = _b[l.x_1] ;
		return scalar beta_lx_2 = _b[l.x_2] ;
		return scalar beta_dx_1 = _b[d.x_1] ;
		return scalar beta_dx_2 = _b[d.x_2] ;
		return scalar tstat_dx_1 = abs(_b[D.x_1]/_se[D.x_1]) ; 
		return scalar tstat_lx_1 = abs(_b[L.x_1]/_se[L.x_1]) ; 
		return scalar tstat_dx_2 = abs(_b[D.x_2]/_se[D.x_2]) ; 
		return scalar tstat_lx_2 = abs(_b[L.x_2]/_se[L.x_2]) ;
		return scalar tstat_ly = _b[L.y]/_se[L.y] ; 
		matrix V=e(V) ;
		matlist V ;
		/*Compute LRM of x_1 on y.*/
		local LRM_1 = _b[L.x_1]/abs(_b[L.y]) ;
		local var_LRM_1 = (1/_b[L.y]^2)*V[4,4]+(_b[L.x_1]^2/_b[L.y]^4)*V[1,1]
		-2*(_b[L.x_1]/_b[L.y]^3)*V[4,1] ;
		local se_LRM_1=sqrt(`var_LRM_1') ;
		return scalar tstat_LRM_1 = abs(`LRM_1'/`se_LRM_1') ;
		/*Compute LRM of x_2 on y.*/
		local LRM_2 = _b[L.x_2]/abs(_b[L.y]) ;
		local var_LRM_2 = (1/_b[L.y]^2)*V[5,5]+(_b[L.x_2]^2/_b[L.y]^4)*V[1,1]
		-2*(_b[L.x_2]/_b[L.y]^3)*V[5,1] ;
		local se_LRM_2=sqrt(`var_LRM_2') ;
		return scalar tstat_LRM_2 = abs(`LRM_2'/`se_LRM_2') ;
		return scalar obs=`obs' ;
		return scalar p=`p' ;
		return scalar q=`q' ;
		return scalar r=`r' ;
		
		reg d.y l.y ; /*To check if our proposed adjustment alleviates bias in the coefficient on ly in the ECM.*/
		local beta_ly_diff = _b[L.y] ;
		return scalar beta_ly_diff = `beta_ly_diff' ;
		return scalar beta_ly_ct = `beta_ly' - `beta_ly_diff' ;
end ;
coint ;

#d ;
postfile coint 
obs p q r 
				fsig_df_y fsig_df_x_1 fsig_df_x_2 
				fsig_ecm_mac_nc fsig_ecm_mac_c fsig_ecm_t fsig_ecm_t_2 
				fsig_lx_1_0 fsig_LRM_1_0 
				fsig_lx_2_0 fsig_LRM_2_0 
				fsig_lx_1_0_dy fsig_LRM_1_0_dy 
				fsig_lx_2_0_dy fsig_LRM_2_0_dy 
				fsig_lx_1_ecm_mac_nc fsig_LRM_1_ecm_mac_nc 
				fsig_lx_1_ecm_mac_c fsig_LRM_1_ecm_mac_c 
				fsig_lx_2_ecm_mac_nc fsig_LRM_2_ecm_mac_nc 
				fsig_lx_2_ecm_mac_c fsig_LRM_2_ecm_mac_c 
				fsig_lx_1_ecm_mac_nc_df_xy fsig_LRM_1_ecm_mac_nc_df_xy 
				fsig_lx_1_ecm_mac_c_df_xy fsig_LRM_1_ecm_mac_c_df_xy 
				fsig_lx_2_ecm_mac_nc_df_xy fsig_LRM_2_ecm_mac_nc_df_xy 
				fsig_lx_2_ecm_mac_c_df_xy fsig_LRM_2_ecm_mac_c_df_xy 
				fsig_lx_1_ecm_mac_nc_df_y fsig_LRM_1_ecm_mac_nc_df_y 
				fsig_lx_1_ecm_mac_c_df_y fsig_LRM_1_ecm_mac_c_df_y 
				fsig_lx_2_ecm_mac_nc_df_y fsig_LRM_2_ecm_mac_nc_df_y 
				fsig_lx_2_ecm_mac_c_df_y fsig_LRM_2_ecm_mac_c_df_y 
				fsig_lx_1_ecm_t fsig_LRM_1_ecm_t 
				fsig_lx_1_ecm_t_2 fsig_LRM_1_ecm_t_2 
				fsig_lx_1_ecm_t_2_df_y fsig_LRM_1_ecm_t_2_df_y 
				fsig_lx_2_ecm_t fsig_LRM_2_ecm_t 
				fsig_lx_2_ecm_t_2 fsig_LRM_2_ecm_t_2 
				fsig_lx_2_ecm_t_2_df_y fsig_LRM_2_ecm_t_2_df_y 
				beta_mean_ly beta_mean_ly_ecm_mac_c_dy beta_mean_dx_1 beta_mean_lx_1 beta_mean_dx_2 beta_mean_lx_2 
				beta_mean_ly_ct beta_mean_ly_ct_ecm_mac_c_dy 
				using "$nocoint\results\nocoint", replace ; 
foreach obs of numlist 130 160 200 { ;
foreach p of numlist 0.9 0.95 1 { ;
foreach q of numlist 0.9 0.95 1 { ;
foreach r of numlist 0.9 0.95 1 { ;
				simul obs=r(obs) p=r(p) q=r(q) r=r(r) 
				p_value_df_y=r(p_value_df_y) p_value_df_x_1=r(p_value_df_x_1) p_value_df_x_2=r(p_value_df_x_2) 
				tstat_dx_1=r(tstat_dx_1) tstat_lx_1=r(tstat_lx_1) tstat_ly=r(tstat_ly) tstat_LRM_1=r(tstat_LRM_1) 
				tstat_dx_2=r(tstat_dx_2) tstat_lx_2=r(tstat_lx_2) tstat_LRM_2=r(tstat_LRM_2) 
				beta_ly=r(beta_ly) beta_ly_ct=r(beta_ly_ct) beta_lx_1=r(beta_lx_1) beta_lx_2=r(beta_lx_2) 
				beta_dx_1=r(beta_dx_1) beta_dx_2=r(beta_dx_2), 
				reps(2000): 
				coint, obs(`obs') p(`p') q(`q') r(`r') ;
				local obs_n =`obs'-100 ; 
				local obs_df =`obs'-100-6 ; /*Six explanatory variables including a constant.*/
				local obs_ecm_mac_nc =`obs'-100-5 ; /*Five explanatory variables excluding a constant.*/
				local cv_t_one = invttail(`obs_df',0.05) ;
				local cv_t_two = invttail(`obs_df',0.025) ;
				local cv_ecm_mac_c = -3.5057-3.27/`obs_df'+1.1/(`obs_df'^2)-34/(`obs_df'^3) ; /*From MacKinnon and Ericsson (2002)*/
				local cv_ecm_mac_nc = -3.0048-2.11/`obs_ecm_mac_nc'+2.1/(`obs_ecm_mac_nc'^2)-61/(`obs_ecm_mac_nc'^3) ; /*From MacKinnon and Ericsson (2002)*/
				
				/*Results from the DF test. */
				sum p_value_df_y if p_value_df_y>0.05 ; 
				local fsig_df_y = r(N)/20 ; /*The total number of rejecting H0 of I(1) from the DF test.*/
				sum p_value_df_x_1 if p_value_df_x_1>0.05 ; 
				local fsig_df_x_1 = r(N)/20 ;
				sum p_value_df_x_2 if p_value_df_x_2>0.05 ; 
				local fsig_df_x_2 = r(N)/20 ;
				
				/*Examne how often we find evidence of spurious regression for all series. "_0" indicates "no pretest."*/
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' ; 
				local fsig_lx_1_0= r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' ; 
				local fsig_LRM_1_0 = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' ; 
				local fsig_lx_2_0 = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' ; 
				local fsig_LRM_2_0 = r(N)/20 ;
				
				/*Examne how often we find evidence of spurious regression for all series. "_0" indicates "no pretest."*/
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' & p_value_df_y>0.05  ; 
				local fsig_lx_1_0_dy= r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' & p_value_df_y>0.05 ; 
				local fsig_LRM_1_0_dy = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' & p_value_df_y>0.05 ; 
				local fsig_lx_2_0_dy = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' & p_value_df_y>0.05 ; 
				local fsig_LRM_2_0_dy = r(N)/20 ;
				
				
				/*ECM test for cointegration*/
				sum tstat_ly if tstat_ly<=`cv_ecm_mac_nc' ; /*This critical value refers to the MacKinonn critical value for the ECM without a constant.*/
				local fsig_ecm_mac_nc = r(N)/20 ;
				sum tstat_ly if tstat_ly<=`cv_ecm_mac_c' ; /*This critical value refers to the MacKinonn critical value for the ECM with a constant.*/
				local fsig_ecm_mac_c = r(N)/20 ;
				sum tstat_ly if tstat_ly<=-`cv_t_one' ; 
				local fsig_ecm_t = r(N)/20 ;
				sum tstat_ly if tstat_ly<=-`cv_t_two' ; 
				local fsig_ecm_t_2 = r(N)/20 ;
				
				/*Examine how often we find evidence of spurious regression, only for the series for which we find evidence of cointegration by the ECM test for cointegration. */
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' & tstat_ly<=`cv_ecm_mac_nc' ; 
				local fsig_lx_1_ecm_mac_nc = r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' & tstat_ly<=`cv_ecm_mac_nc'; 
				local fsig_LRM_1_ecm_mac_nc = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' & tstat_ly<=`cv_ecm_mac_nc' ; 
				local fsig_lx_2_ecm_mac_nc = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' & tstat_ly<=`cv_ecm_mac_nc'; 
				local fsig_LRM_2_ecm_mac_nc = r(N)/20 ;
				
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' & tstat_ly<=`cv_ecm_mac_c' ; 
				local fsig_lx_1_ecm_mac_c = r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' & tstat_ly<=`cv_ecm_mac_c' ; 
				local fsig_LRM_1_ecm_mac_c = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' & tstat_ly<=`cv_ecm_mac_c' ; 
				local fsig_lx_2_ecm_mac_c = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' & tstat_ly<=`cv_ecm_mac_c' ; 
				local fsig_LRM_2_ecm_mac_c = r(N)/20 ;
				
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' & tstat_ly<=-`cv_t_one' ; 
				local fsig_lx_1_ecm_t = r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' & tstat_ly<=-`cv_t_one' ; 
				local fsig_LRM_1_ecm_t = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' & tstat_ly<=-`cv_t_one' ; 
				local fsig_lx_2_ecm_t = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' & tstat_ly<=-`cv_t_one' ; 
				local fsig_LRM_2_ecm_t = r(N)/20 ;
				
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' & tstat_ly<= -`cv_t_two' ; 
				local fsig_lx_1_ecm_t_2 = r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' & tstat_ly<= -`cv_t_two' ;
				local fsig_LRM_1_ecm_t_2 = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' & tstat_ly<= -`cv_t_two' ; 
				local fsig_lx_2_ecm_t_2 = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' & tstat_ly<= -`cv_t_two' ;
				local fsig_LRM_2_ecm_t_2 = r(N)/20 ;
				
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' & tstat_ly<= -`cv_t_two' & p_value_df_y>0.05 ; 
				local fsig_lx_1_ecm_t_2_df_y = r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' & tstat_ly<= -`cv_t_two' & p_value_df_y>0.05 ;
				local fsig_LRM_1_ecm_t_2_df_y = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' & tstat_ly<= -`cv_t_two' & p_value_df_y>0.05 ; 
				local fsig_lx_2_ecm_t_2_df_y = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' & tstat_ly<= -`cv_t_two' & p_value_df_y>0.05 ;
				local fsig_LRM_2_ecm_t_2_df_y = r(N)/20 ;
				
				/*Examine how often we find evidence of spurious regression, only for the series for which we find evidence of both integration (with the ADF test) in ALL series and cointegration by the ECM test of cointegration. */
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_nc' /*MacKinnon critical value (without a constant)*/ & p_value_df_y>0.05 & p_value_df_x_1>0.05 & p_value_df_x_2>0.05 ; 
				local fsig_lx_1_ecm_mac_nc_df_xy = r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_nc' & p_value_df_y>0.05 & p_value_df_x_1>0.05 & p_value_df_x_2>0.05 ;
				local fsig_LRM_1_ecm_mac_nc_df_xy = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_nc' & p_value_df_y>0.05 & p_value_df_x_1>0.05 & p_value_df_x_2>0.05 ; 
				local fsig_lx_2_ecm_mac_nc_df_xy = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_nc' & p_value_df_y>0.05 & p_value_df_x_1>0.05 & p_value_df_x_2>0.05 ;
				local fsig_LRM_2_ecm_mac_nc_df_xy = r(N)/20 ;
				
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_c' /*MacKinnon critical value (with a constant)*/ & p_value_df_y>0.05 & p_value_df_x_1>0.05 & p_value_df_x_2>0.05 ; 
				local fsig_lx_1_ecm_mac_c_df_xy = r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_c' & p_value_df_y>0.05 & p_value_df_x_1>0.05 & p_value_df_x_2>0.05  ;
				local fsig_LRM_1_ecm_mac_c_df_xy = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_c' & p_value_df_y>0.05 & p_value_df_x_1>0.05 & p_value_df_x_2>0.05 ; 
				local fsig_lx_2_ecm_mac_c_df_xy = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_c' & p_value_df_y>0.05 & p_value_df_x_1>0.05 & p_value_df_x_2>0.05  ;
				local fsig_LRM_2_ecm_mac_c_df_xy = r(N)/20 ;
				
				/*Examine how often we find evidence of spurious regression, only for the series for which we find evidence of both integration (with the ADF test) ONLY in y and cointegration by the ECM test of cointegration. */
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_nc' & p_value_df_y>0.05   ; 
				local fsig_lx_1_ecm_mac_nc_df_y = r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_nc' & p_value_df_y>0.05   ;
				local fsig_LRM_1_ecm_mac_nc_df_y = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_nc' & p_value_df_y>0.05   ; 
				local fsig_lx_2_ecm_mac_nc_df_y = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_nc' & p_value_df_y>0.05   ;
				local fsig_LRM_2_ecm_mac_nc_df_y = r(N)/20 ;
				
				sum tstat_lx_1 if tstat_lx_1>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_c' & p_value_df_y>0.05   ; 
				local fsig_lx_1_ecm_mac_c_df_y = r(N)/20 ;
				sum tstat_LRM_1 if tstat_LRM_1>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_c' & p_value_df_y>0.05    ;
				local fsig_LRM_1_ecm_mac_c_df_y = r(N)/20 ;
				sum tstat_lx_2 if tstat_lx_2>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_c' & p_value_df_y>0.05   ; 
				local fsig_lx_2_ecm_mac_c_df_y = r(N)/20 ;
				sum tstat_LRM_2 if tstat_LRM_2>=`cv_t_two' & tstat_ly<= `cv_ecm_mac_c' & p_value_df_y>0.05    ;
				local fsig_LRM_2_ecm_mac_c_df_y = r(N)/20 ;				
				
				/*Save coefficients*/
				sum beta_ly ; 
				local beta_mean_ly = round(r(mean), .001) ; 
				
				sum beta_ly if tstat_ly<= `cv_ecm_mac_c' & p_value_df_y>0.05 ; 
				local beta_mean_ly_ecm_mac_c_dy = round(r(mean), .001) ; 
				
				sum beta_dx_1 ; 
				local beta_mean_dx_1 = round(r(mean), .001) ; 
				
				sum beta_lx_1 ; 
				local beta_mean_lx_1 = round(r(mean), .001) ; 
				
				sum beta_dx_2 ; 
				local beta_mean_dx_2 = round(r(mean), .001) ; 
				
				sum beta_lx_2 ; 
				local beta_mean_lx_2 = round(r(mean), .001) ; 
				
				sum beta_ly_ct ;
				local beta_mean_ly_ct = round(r(mean), .001) ;
				
				sum beta_ly_ct if tstat_ly<= `cv_ecm_mac_c' & p_value_df_y>0.05  ;
				local beta_mean_ly_ct_ecm_mac_c_dy = round(r(mean), .001) ;
				
				post coint (`obs') (`p') (`q') (`r') 
				(`fsig_df_y') (`fsig_df_x_1') (`fsig_df_x_2') 
				(`fsig_ecm_mac_nc') (`fsig_ecm_mac_c') (`fsig_ecm_t') (`fsig_ecm_t_2') 
				(`fsig_lx_1_0') (`fsig_LRM_1_0') 
				(`fsig_lx_2_0') (`fsig_LRM_2_0') 
				(`fsig_lx_1_0_dy') (`fsig_LRM_1_0_dy') 
				(`fsig_lx_2_0_dy') (`fsig_LRM_2_0_dy') 
				(`fsig_lx_1_ecm_mac_nc') (`fsig_LRM_1_ecm_mac_nc') 
				(`fsig_lx_1_ecm_mac_c') (`fsig_LRM_1_ecm_mac_c') 
				(`fsig_lx_2_ecm_mac_nc') (`fsig_LRM_2_ecm_mac_nc') 
				(`fsig_lx_2_ecm_mac_c') (`fsig_LRM_2_ecm_mac_c') 
				(`fsig_lx_1_ecm_mac_nc_df_xy') (`fsig_LRM_1_ecm_mac_nc_df_xy') 
				(`fsig_lx_1_ecm_mac_c_df_xy') (`fsig_LRM_1_ecm_mac_c_df_xy') 
				(`fsig_lx_2_ecm_mac_nc_df_xy') (`fsig_LRM_2_ecm_mac_nc_df_xy') 
				(`fsig_lx_2_ecm_mac_c_df_xy') (`fsig_LRM_2_ecm_mac_c_df_xy') 
				(`fsig_lx_1_ecm_mac_nc_df_y') (`fsig_LRM_1_ecm_mac_nc_df_y') 
				(`fsig_lx_1_ecm_mac_c_df_y') (`fsig_LRM_1_ecm_mac_c_df_y') 
				(`fsig_lx_2_ecm_mac_nc_df_y') (`fsig_LRM_2_ecm_mac_nc_df_y') 
				(`fsig_lx_2_ecm_mac_c_df_y') (`fsig_LRM_2_ecm_mac_c_df_y') 
				(`fsig_lx_1_ecm_t') (`fsig_LRM_1_ecm_t') 
				(`fsig_lx_1_ecm_t_2') (`fsig_LRM_1_ecm_t_2') 
				(`fsig_lx_1_ecm_t_2_df_y') (`fsig_LRM_1_ecm_t_2_df_y') 
				(`fsig_lx_2_ecm_t') (`fsig_LRM_2_ecm_t') 
				(`fsig_lx_2_ecm_t_2') (`fsig_LRM_2_ecm_t_2') 
				(`fsig_lx_2_ecm_t_2_df_y') (`fsig_LRM_2_ecm_t_2_df_y') 
				(`beta_mean_ly') (`beta_mean_ly_ecm_mac_c_dy') (`beta_mean_dx_1') (`beta_mean_lx_1') (`beta_mean_dx_2') (`beta_mean_lx_2') 
				(`beta_mean_ly_ct') (`beta_mean_ly_ct_ecm_mac_c_dy') ;
				} ;
				} ;
				} ;
				} ;
				postclose coint ;			
clear ;

#d ;
cap mkdir "$nocoint\tables" ;
/*Replicate Table 1*/
use "$nocoint\results\nocoint", clear ;
drop if p>0.91 & p<0.96 ;
drop if q>0.91 & q<0.96 ;
drop if r>0.91 & r<0.96 ;
keep obs p q r fsig_lx_1_0 fsig_lx_1_ecm_mac_c_df_y ;
order obs p q r fsig_lx_1_0 fsig_lx_1_ecm_mac_c_df_y ;
outsheet using "$nocoint\tables\table1.csv", comma replace ;

#d ;
/*Replicate Table A-6*/
use "$nocoint\results\nocoint", clear ;
keep obs p q r fsig_lx_1_0 fsig_lx_1_ecm_t_2 fsig_lx_1_ecm_mac_c_df_y  ;
order obs p q r fsig_lx_1_0 fsig_lx_1_ecm_t_2 fsig_lx_1_ecm_mac_c_df_y ;
outsheet using "$nocoint\tables\tableA-4.csv", comma replace ;

